<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "personnel_class".
 *
 * @property integer $personnel_class_id
 * @property string $class_name
 * @property integer $parent_id
 * @property integer $sort
 * @property integer $is_show
 */
class PersonnelClass extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'personnel_class';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['class_name'], 'required'],
            [['parent_id', 'sort', 'is_show'], 'integer'],
            [['class_name'], 'string', 'max' => 50],
            [['sort'], 'default', 'value' => 50],
            [['parent_id'], 'exist', 'skipOnError' => true, 'targetClass' => PersonnelClass::className(), 'targetAttribute' => ['parent_id' => 'personnel_class_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'personnel_class_id' => '蛋糕作品分类ID',
            'class_name' => '分类名',
            'parent_id' => '父级id',
            'sort' => '排序',
            'is_show' => '是否显示',
        ];
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getParent()
    {
        return $this->hasOne(PersonnelClass::className(), ['personnel_class_id' => 'parent_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPersonnelClasses()
    {
        return $this->hasMany(PersonnelClass::className(), ['parent_id' => 'personnel_class_id']);
    }
}
